package com.hc.controller;

import com.hc.entity.Payment;
import com.hc.service.PaymentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/provider")
@Slf4j
public class ProviderController {

    @Resource
    private PaymentService paymentService;

    @PostMapping("/create")
    public Result createPayment(@RequestBody Payment payment){
        int res = paymentService.createPayment(payment);
        log.info("添加结果："+res);
        if(res ==1) {
            return ResultUtil.success(200,"添加成功！");
        }else {
            return ResultUtil.fail(400,"添加失败");
        }
    }

    @GetMapping("/get/{id}")
    public Result<Payment> getPayment(@PathVariable("id")Integer id){
        Payment payment = paymentService.getPaymentById(id);
        log.info("查询结果是："+payment);
        if(payment != null) {
            return ResultUtil.success(200,"查询成功！",payment);
        }else {
            return ResultUtil.fail(400,"查询失败",null);
        }
    }
}
